/*******************************************************************************
 * Copyright (c) 2006 Ultimate Technology, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bojan Vukojevic - initial API and implementation
 *     Nick Panin - adopting for modern Java && Eclipse
 *******************************************************************************/
package com.ultimatetech.cim.views;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import javax.wbem.cim.CIMClass;
import javax.wbem.cim.CIMException;
import javax.wbem.cim.CIMInstance;
import javax.wbem.cim.CIMMethod;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.client.CIMClient;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart;

import com.ultimatetech.cim.CIMPlugin;
import com.ultimatetech.cim.dialogs.FindClass;
import com.ultimatetech.cim.dialogs.NewInstanceDialog;
import com.ultimatetech.cim.dialogs.UsernamePasswordDialog;
import com.ultimatetech.cim.preferences.CIMPreferencePage;
import com.ultimatetech.cim.views.content.CIMConnect;
import com.ultimatetech.cim.views.content.COPComparator;
import com.ultimatetech.cim.views.content.ClassNames;


/**
 * This sample class demonstrates how to plug-in a new
 * workbench view. The view shows data obtained from the
 * model. The sample creates a dummy model on the fly,
 * but a real implementation would connect to the model
 * available either in this or another plug-in (e.g. the workspace).
 * The view is connected to the model using a content provider.
 * <p>
 * The view uses a label provider to define how model
 * objects should be presented in the view. Each
 * view can present the same model objects using
 * different labels and icons, if needed. Alternatively,
 * a single label provider can be shared between views
 * in order to ensure that objects of the same type are
 * presented in the same way everywhere.
 * <p>
 */

public class CIMExplorerView extends ViewPart {
	private TreeViewer viewer;
	private DrillDownAdapter drillDownAdapter;
	private Action refreshTreeAction;
	private Action switchUserAction;
	private Action searchForClassAction;
	private Action doubleClickAction;
	private Action createInstanceAction;
	private CIMPropChangeListener propChangeListener ;
	private TreeParent invisibleRoot;
	
	class CIMPropChangeListener implements IPropertyChangeListener {

		public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
			boolean cimPropchanged = false;
			if (event.getProperty().equals(CIMPreferencePage.PreferenceNames.CIM_HOST)) {
				cimPropchanged = true;
			} else if(event.getProperty().equals(CIMPreferencePage.PreferenceNames.CIM_NAMESPACE)){
				cimPropchanged = true;
			} else if(event.getProperty().equals(CIMPreferencePage.PreferenceNames.CIM_PORT)){
				cimPropchanged = true;
			}else if(event.getProperty().equals(CIMPreferencePage.PreferenceNames.CIM_FILTER)){
				cimPropchanged = true;
			}
			if(cimPropchanged){		
				CIMPlugin.getDefault().setCIMPassword(null);
				viewer.getTree().removeAll();
				viewer.refresh();
				invisibleRoot = null;
				viewer.setContentProvider(new ViewContentProvider());
				viewer.setLabelProvider(new ViewLabelProvider());
				//viewer.setSorter(new NameSorter());
				viewer.setInput(getViewSite());	
				
			}
		}
 	}
	
	class ExpandTreeListener implements TreeListener 
	{
		@Override
		public void treeCollapsed(TreeEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void treeExpanded(TreeEvent event) 
		{
			final TreeParent tp = (TreeParent)event.item.getData();

            if(tp.getChildren() != null && tp.getChildren().length > 0 
					&& tp.getChildren()[0].getName().startsWith("Loading"))
			{
				Preferences pref = CIMPlugin.getDefault().getPluginPreferences();
				CIMClient client = CIMConnect.connect(
						pref.getString(CIMPreferencePage.PreferenceNames.IS_SECURE),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_HOST),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_PORT),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_NAMESPACE)
				);
				
                viewer.expandToLevel(tp, 1);
                viewer.refresh(tp);

				TreeObject loading = tp.getChildren()[0];
				/*
				 * class
				 *   |_Walk assoc
				 *         |_RefClass1
				 *              |_Loading associations...
				 *              |_class
				 */
				try {
					if(tp.getChildren()[0].getName().startsWith("Loading associations"))
					{
                        CIMObjectPath x = ((TreeObject) tp.getParent().getParent()).getCop();
                        String className = tp.getName();
                        Enumeration<?> en = client.associators(
                                x,
                                className,
                                null, //result class
                                null, //role
                                null, //result role
                                false, //include qualifiers
                                false, //include class origin
                                null //which properties to include in the response - all
                        );

                        int num = 0;
                        while(en.hasMoreElements()) 
                        {
                            num++;
                            Object o = en.nextElement();
                            if(o instanceof CIMInstance)
                            {
                                addInstanceToTree(tp, (CIMInstance)o);
                            }
                            else 
                            {
                                CIMClass cc = (CIMClass)o;
                                CIMObjectPath cassoc = cc.getObjectPath();
                                TreeClass tni = new TreeClass(cassoc.getObjectName());//TODO: this might be an istance

                                tni.setCop(cassoc);
                                tp.addChild(tni);
                                
                                //add instances node
                                TreeParent p1 = new TreeParent("Instances");
                                p1.setCop(cassoc);
                                TreeObject p2 = new TreeObject("Loading instance names...");
                                p1.addChild(p2);
                                tni.addChild(p1);
                                
                                //add walk assoc node
                                TreeParent to = new TreeParent("Walk associations (using class)");
                                tni.addChild(to);
                                TreeObject rtn = new TreeObject("Loading references...");
                                to.addChild(rtn);
                            }
                            //viewer.refresh(tp, true);
                            //viewer.refresh(tni, true);
                        }
                        if(num == 0)
                        {
                            TreeObject to = new TreeObject("No instances returned");
                            tp.addChild(to);
                        }
                    }
                    else
                        if (tp.getName().equals("Methods"))
                        {
                            Vector<?> v = client.getClass(tp.getCop()).getAllMethods();
                            int sz = v == null ? 0 : v.size();
                            if (sz == 0)
                            {
                                TreeObject to = new TreeObject("No methods detected");
                                tp.addChild(to);
                            }
                            for (int i = 0; i < v.size(); i++)
                            {
                                CIMMethod cm = (CIMMethod) v.get(i);
                                TreeNodeMethod tnm = new TreeNodeMethod(cm);
                                tp.addChild(tnm);
                                viewer.refresh(tp, true);
                                viewer.refresh(tnm, true);
                            }
                            tp.removeChild(loading);

                        }
                        else
                            if (tp.getName().equals("Instances"))
                            {
                                Enumeration<?> en = client.enumerateInstances(tp.getCop());
                                int num = 0;
                                while (en.hasMoreElements())
                                {
                                    num++;
                                    CIMInstance ci = (CIMInstance) en.nextElement();
                                    addInstanceToTree(tp, ci);
                                }
                                if (num == 0)
                                {
                                    TreeObject to = new TreeObject("No instances returned");
                                    tp.addChild(to);
                                }
                            }
                            else
                                if (tp.getName().startsWith("Walk associations"))
                                {
                					/*
                					 * class
                					 *   |_Walk associations
                					 *   	   |_RefClass1
                					 *   			|_Loading associations...
                					 *   			|_class
                					 */
                                    viewer.expandToLevel(tp, 1);
                                    Enumeration<?> en = client.referenceNames(tp.getParent().getCop());
                                    List<CIMObjectPath> sortedRefs = new ArrayList<CIMObjectPath>();

                                    int num = 0;
                                    while (en.hasMoreElements())
                                    {
                                        sortedRefs.add((CIMObjectPath) en.nextElement());
                                    }
                                    Collections.sort(sortedRefs, new COPComparator());
                                    int sz = sortedRefs.size();
                                    String lastClassName = "";
                                    for (int i = 0; i < sz; i++)
                                    {
                                        num++;
                                        CIMObjectPath ci = (CIMObjectPath) sortedRefs.get(i);
                                        if (lastClassName.equals(ci.getObjectName()))
                                        {
                                            continue;
                                        }
                                        lastClassName = ci.getObjectName();
                                        TreeClassRef tni = new TreeClassRef(ci);
                                        tp.addChild(tni);
                                        String nodeName = "Loading associations (starting from class)... ";
                                        if (tp.getName().indexOf("instance") >= 0)
                                        {
                                            nodeName = "Loading associations (starting from instance)... ";
                                        }
                                        TreeObject to = new TreeObject(nodeName);
                                        tni.addChild(to);
                                    }
                                    if (num == 0)
                                    {
                                        TreeObject to = new TreeObject("No references returned");
                                        tp.addChild(to);
                                    }
                                }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                tp.removeChild(loading);
//                viewer.getTree().update();
                viewer.expandToLevel(tp, 1);
                viewer.refresh(tp, true);
                // viewer.getTree().update();
            }
        }
    }	
	
	private void addInstanceToTree(TreeParent tp, CIMInstance ci) {			
		TreeNodeInstance tni = new TreeNodeInstance(ci);
		tp.addChild(tni);
		// add walk assoc node
		TreeParent to = new TreeParent("Walk associations (using instance)");
		tni.addChild(to);
		TreeObject rtn = new TreeObject("Loading references...");
		to.addChild(rtn);
//		viewer.refresh(tp, true);
//		viewer.refresh(tni, true);
	}

	
	class TreeClass extends TreeParent {
		public TreeClass(String name) {
			super(name);
		}
		
	}
	class TreeNodeMethod extends TreeObject {
		CIMMethod cimMethod = null;
		public TreeNodeMethod(CIMMethod cm){
			super(cm.getName());
			cimMethod = cm;			
		}
	}
	class TreeNodeInstance extends TreeParent {
		CIMInstance cimInstance = null;
		public TreeNodeInstance(CIMInstance ci){
			super(ci.getClassName());
			cimInstance = ci;
			setCop(ci.getObjectPath());
		}
	}
	class TreeClassRef extends TreeClass {
		
		public TreeClassRef(CIMObjectPath cc){
			super(cc.getObjectName());
			setCop(cc);
		}
	}
		

	class ViewContentProvider implements IStructuredContentProvider, 
										   ITreeContentProvider {		

		public void inputChanged(Viewer v, Object oldInput, Object newInput)
		{}
		
		public void dispose()
		{}
		
		public Object[] getElements(Object parent) 
		{
			if (parent.equals(getViewSite())) 
			{
				if (invisibleRoot == null)
				{
				    initialize();
				}
				return getChildren(invisibleRoot);
			}
			return getChildren(parent);
		}
		
		public Object getParent(Object child)
		{
			if (child instanceof TreeObject) 
			{
				return ((TreeObject)child).getParent();
			}
			return null;
		}
		
		public Object [] getChildren(Object parent) 
		{
			if (parent instanceof TreeParent) 
			{
				return ((TreeParent)parent).getChildren();
			}
			return new Object[0];
		}
		
		public boolean hasChildren(Object parent) 
		{
			if (parent instanceof TreeParent)
			{
				return ((TreeParent)parent).hasChildren();
			}
			return false;
		}
		private void initialize() {
			Preferences pref = CIMPlugin.getDefault().getPluginPreferences();
			String ch = pref.getString(CIMPreferencePage.PreferenceNames.CIM_HOST);
			ch = ch == null || "".equals(ch)?
					"localhost" : ch;
			TreeParent root = new TreeParent(
					pref.getString(CIMPreferencePage.PreferenceNames.CIM_NAMESPACE) + "@" +
					ch);			
			
			ClassNames cn = new ClassNames(pref);
			List cnList = cn.getClassNames();					
			for(int i = 0; i < cnList.size(); i++){
				CIMObjectPath cc = (CIMObjectPath)cnList.get(i);
				TreeClass p = new TreeClass(cc.getObjectName());
				p.setCop(cc);
				root.addChild(p);
				
				TreeParent p1 = new TreeParent("Instances");
				p1.setCop(cc);
				TreeObject p2 = new TreeObject("Loading instance names....");
				p1.addChild(p2);
				p.addChild(p1);
				
				p1 = new TreeParent("Walk associations (using class)");
				//p1.setCop(cc);
				p2 = new TreeObject("Loading reference names....");
				p1.addChild(p2);
				p.addChild(p1);
				
			}
			
			invisibleRoot = new TreeParent("");
			invisibleRoot.addChild(root);
		}
	}
	class ViewLabelProvider extends LabelProvider {

		public String getText(Object obj) {
			return obj.toString();
		}
		public Image getImage(Object obj) {
			String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
			try {
				if(obj instanceof TreeClassRef){
					return CIMPlugin.getDefault().getImage("icons/assoc_class_obj.gif");
				}
			if(obj instanceof TreeClass){
				return CIMPlugin.getDefault().getImage(
						"icons/class_obj.gif");
			}
			if(obj instanceof TreeNodeInstance){
				return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
			}

			if (obj instanceof TreeParent){
				if(((TreeParent)obj).getName().startsWith("Walk")){
					return CIMPlugin.getDefault().getImage(
							"icons/walk_assoc_obj2.gif");
				} else if(((TreeParent)obj).getName().startsWith("Instance")){
					return CIMPlugin.getDefault().getImage(
							"icons/instance_obj.gif");
				} else {
					imageKey = ISharedImages.IMG_OBJ_FOLDER;
				}
			} else if(obj instanceof TreeObject){
				if(((TreeObject)obj).getName().startsWith("No ")){
					imageKey = ISharedImages.IMG_OBJS_WARN_TSK;
				} else if(obj instanceof TreeNodeMethod){
					return CIMPlugin.getDefault().getImage(
					"icons/methpub_obj.gif");
				}
			}
			}catch(Throwable t){
				t.printStackTrace();
			}
			return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
		}
	}
	class NameSorter extends ViewerSorter {
	}

	/**
	 * The constructor.
	 */
	public CIMExplorerView() {
	}

	/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		drillDownAdapter = new DrillDownAdapter(viewer);
		viewer.setContentProvider(new ViewContentProvider());
		viewer.setLabelProvider(new ViewLabelProvider());
		//viewer.setSorter(new NameSorter());
		viewer.setInput(getViewSite());
		viewer.getTree().addTreeListener(new ExpandTreeListener());
		makeActions();
		hookContextMenu();
		hookDoubleClickAction();
		contributeToActionBars();
		propChangeListener = new CIMPropChangeListener();
		CIMPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(propChangeListener);
	}

	private void hookContextMenu() {
		MenuManager menuMgr = new MenuManager("#PopupMenu");
		menuMgr.setRemoveAllWhenShown(true);
		menuMgr.addMenuListener(new IMenuListener() {
			public void menuAboutToShow(IMenuManager manager) {
				CIMExplorerView.this.fillContextMenu(manager);
			}
		});
		Menu menu = menuMgr.createContextMenu(viewer.getControl());
		viewer.getControl().setMenu(menu);
		getSite().registerContextMenu(menuMgr, viewer);
	}
	
	private void contributeToActionBars() {
		IActionBars bars = getViewSite().getActionBars();
		fillLocalPullDown(bars.getMenuManager());
		fillLocalToolBar(bars.getToolBarManager());
	}

	private void fillLocalPullDown(IMenuManager manager) {
		manager.add(refreshTreeAction);
		manager.add(new Separator());
		manager.add(switchUserAction);
		manager.add(searchForClassAction);
	}

	private void fillContextMenu(IMenuManager manager) {
		manager.add(refreshTreeAction);
		manager.add(switchUserAction);
		manager.add(searchForClassAction);
		manager.add(new Separator());
		drillDownAdapter.addNavigationActions(manager);
		// Other plug-ins can contribute there actions here
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
		TreeItem[] ti = viewer.getTree().getSelection();
		Object tc = ti[0].getData();
		if(tc instanceof TreeClass){
			manager.add(createInstanceAction);
		}
	}
	
	private void fillLocalToolBar(IToolBarManager manager) {
		manager.add(refreshTreeAction);
		manager.add(switchUserAction);
		manager.add(searchForClassAction);
		manager.add(new Separator());
		drillDownAdapter.addNavigationActions(manager);		
	}

	public void refreshAllTreeNodes() {
		viewer.getTree().removeAll();
		invisibleRoot = null;
		viewer.setContentProvider(new ViewContentProvider());
		if(invisibleRoot != null && 
				invisibleRoot.getChildren() != null && 
				invisibleRoot.getChildren().length > 0) {
			viewer.expandToLevel(invisibleRoot.getChildren()[0], 1);
			viewer.refresh(invisibleRoot);
		}
	}
	
	private void makeActions() {
		refreshTreeAction = new Action() {
			public void run() {
				refreshAllTreeNodes();
				showMessage("Tree refreshed");
			}

			
		};
		refreshTreeAction.setText("Refresh tree");
		refreshTreeAction.setToolTipText("Reload all classes in the tree");
		refreshTreeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
			getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
		
		switchUserAction = new Action() {
			public void run() {
				UsernamePasswordDialog upDiag = 
					new UsernamePasswordDialog(
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
				upDiag.open();//does it block here?)
				if(upDiag.getReturnCode() == Dialog.OK) {
					CIMPlugin.getDefault().setCIMUsername(upDiag.getEnteredUsername());
					CIMPlugin.getDefault().setCIMPassword(upDiag.getEnteredPassword());
					refreshAllTreeNodes();
					showMessage("Tree refreshed");
				}
			}
		};
		switchUserAction.setText("Switch user");
		switchUserAction.setToolTipText("Enter username and password");
		switchUserAction.setImageDescriptor(
				CIMPlugin.getImageDescriptor("icons/login.gif"));
		searchForClassAction = new Action() {
			public void run() {
				FindClass fcDiag = 
					new FindClass(
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
							((TreeParent)(invisibleRoot.getChildren()[0])).getChildren());							
				fcDiag.open();
				if(fcDiag.getReturnCode() == Dialog.OK) {
					int i = fcDiag.getSelectedItemIndex();
					TreeItem tip = viewer.getTree().getItem(0);
					TreeItem ti = tip.getItem(i);
					viewer.getTree().setSelection(new TreeItem[] {ti});					
				}
			}
		};
		searchForClassAction.setText("Search for class");
		searchForClassAction.setToolTipText("Search for class in a tree");
		searchForClassAction.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/search.gif"));
		
		
		createInstanceAction = new Action() {
			public void run() {
				TreeClass tc = (TreeClass)viewer.getTree().getSelection()[0].getData();
				Preferences pref = CIMPlugin.getDefault().getPluginPreferences();
				CIMClient client = CIMConnect.connect(
						pref.getString(CIMPreferencePage.PreferenceNames.IS_SECURE),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_HOST),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_PORT),
						pref.getString(CIMPreferencePage.PreferenceNames.CIM_NAMESPACE)
						);
				NewInstanceDialog niDiag;
				try {
					CIMClass cc = client.getClass(tc.getCop(), false, false, true, null);
					niDiag = new NewInstanceDialog(
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
							cc);
					niDiag.open();
					if(niDiag.getReturnCode() == Dialog.OK) {
						client.createInstance(tc.getCop(), niDiag.getCIMInstance());
						showMessage("Instance created");					
					}
				} catch (CIMException e) {
					ErrorDialog ed = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
							"Error", "Create instance failed:" + e.getMessage(), 
							new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
							IStatus.ERROR);
					ed.open();
					e.printStackTrace();
				}							
				
			}
		};
		createInstanceAction.setText("Create instance");
		createInstanceAction.setToolTipText("Create instance of this class");
		//searchForClassAction.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/search.gif"));
		
		
		doubleClickAction = new Action() {
			public void run() {
				ISelection selection = viewer.getSelection();
				Object obj = ((IStructuredSelection)selection).getFirstElement();
				try {
				if(obj instanceof TreeNodeInstance) {
					//showMessage("Double-click detected on "+obj.toString());
					
						CIMInstanceView civ = (CIMInstanceView) 
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(
									"com.ultimatetech.cim.views.CIMInstanceView");
						civ.setCIMInstance(((TreeNodeInstance)obj).cimInstance);					
				} else if(obj instanceof TreeClass){
					//open CIMClassHierarchyView
					CIMClassHierarchyView view = (CIMClassHierarchyView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(
					"com.ultimatetech.cim.views.CIMClassHierarchyView");
					view.setCimObjectPath(((TreeClass)obj).getCop());
				}
				} catch (PartInitException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}					
				
			}
		};
	}

	private void hookDoubleClickAction() {
		viewer.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(DoubleClickEvent event) {
				doubleClickAction.run();
			}
		});
	}
	private void showMessage(String message) {
		MessageDialog.openInformation(
			viewer.getControl().getShell(),
			"CIM Explorer",
			message);
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		viewer.getControl().setFocus();
	}
	public void dispose() {
		CIMPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(propChangeListener);
		super.dispose();
	}
}
